// antd 按需加载
import { Toast } from '@ant-design/react-native';
import { Actions } from 'react-native-router-flux';

import store from '../store/store.js'
import * as ActionTypes from '../constants/constants.js'
import { isUser, isWxUser, path, saveData, loadData, removeData, requestMessage } from '../util/utils.js'
import request from '../api/request.js'
import { data } from '../util/images.js';

export async function sendAuthCode(options, callback) {
    const { dispatch } = this.props
    const loading = Toast.loading('获取验证码中', 0, null, false)
    const res = await request.MemberController.authCode(options)
    if (res.data.code == 200) {
        this.setState({
            disable: true,
        });
        let send = 60;
        this.time = setInterval(() => {
            this.setState({
                send: `${send}s后重新获取`,
            });
            send--;
            if (send < 0) {
                clearInterval(this.time);
                this.setState({
                    disable: false,
                    send: '获取验证码',
                });
            }
        }, 1000);
    }
    return requestMessage(res, loading, {
        success: '验证码已发送到您的手机',
        error: res.data.message,
    })
    // callback ? callback(res.data) : null
}


export async function logout(options, callback) {
    console.log('退出登录')
    store.dispatch({
        type: ActionTypes.authReset,
        data: {}
    })
    store.dispatch({
        type: ActionTypes.userInfoReset,
        data: {}
    })
    removeData('authorization')
    removeData('userInfo')
    Actions.login()
}


// export async function userInfo(options, callback) {
//     const { dispatch } = this.props
//     const res = await request.MemberController.userInfo(options)
//     store.dispatch({
//         type: ActionTypes.userInfo,
//         data: res.data
//     })
//     saveData('userInfo', res.data)
// }
